import { Component, OnInit, Inject, HostBinding, ChangeDetectionStrategy } from '@angular/core';
import { MatDialog, MAT_DIALOG_DATA } from '@angular/material';
import { NewTaskComponent } from '../new-task/new-task.component';
import { CopyTaskComponent } from '../copy-task/copy-task.component';
import { ConfirmDialogComponent } from 'src/app/shared/confirm-dialog/confirm-dialog.component';
import { NewTaskListComponent } from '../new-task-list/new-task-list.component';
import {routeAnimation} from '../../my-animations/router.animation';

@Component({
  selector: 'app-task-home',
  templateUrl: './task-home.component.html',
  styleUrls: ['./task-home.component.scss'],
  animations:[
    routeAnimation
  ],
  //ChangeDetectionStrategy.OnPush 不用检查当前组件树是否变化  除非 你告诉我  手动设置
  changeDetection:ChangeDetectionStrategy.OnPush
})
export class TaskHomeComponent implements OnInit {
  @HostBinding('@routeAnimation') state:string;
  lists = [
    {
      id: 1,
      name: '代办',
      tasks: [
        {
          id: 1,
          desc: '任务一:去买杯咖啡',
          completed: true,
          priority: 3,
          ovner: {
            id: 1,
            name: '张三',
            avatar: 'avatars:svg-1',
          },
          dueDate: new Date(),
          reminder: new Date(),
        },
        {
          id: 2,
          desc: '任务一:去买杯咖啡',
          completed: false,
          priority: 2,
          ovner: {
            id: 2,
            name: '张三',
            avatar: 'avatars:svg-2',
          },
          dueDate: new Date(),
        },
      ],
    },
    {
      id: 2,
      name: '进行中',
      tasks: [
        {
          id: 1,
          desc: '任务一:去买杯咖啡',
          completed: false,
          priority: 2,
          ovner: {
            id: 1,
            name: '张三',
            avatar: 'avatars:svg-3',
            reminder: new Date(),
          },
          dueDate: new Date(),
        },
        {
          id: 2,
          desc: '任务一:去买杯咖啡',
          completed: false,
          priority: 1,
          ovner: {
            id: 2,
            name: '张三',
            avatar: 'avatars:svg-4',
          },
          dueDate: new Date(),
          reminder: new Date(),
        },
      ],
    },
    {
      id: 3,
      name: '已完成',
      tasks: [
        {
          id: 1,
          desc: '任务一:去买杯咖啡',
          completed: false,
          priority: 2,
          ovner: {
            id: 1,
            name: '张三',
            avatar: 'avatars:svg-5',
          },
          dueDate: new Date(),
        },
        {
          id: 2,
          desc: '任务一:去买杯咖啡',
          completed: false,
          priority: 3,
          ovner: {
            id: 2,
            name: '张三',
            avatar: 'avatars:svg-6',
          },
          dueDate: new Date(),
          reminder: new Date(),
        },
      ],
    },
  ]
  constructor(private dialog: MatDialog) { }

  ngOnInit() {
  }

  launchNewTaskDialg() {
    this.dialog.open(NewTaskComponent,{data:{title:"新建任务"}})
  }
  lanuchMoveAllDialg(){
   this.dialog.open(CopyTaskComponent,{data:{lists:this.lists}}) 
  }

  lanuchTaskClickDialg(task){
    this.dialog.open(NewTaskComponent,{data:{title:"修改任务",task:task}})
  }
  lanuchDelectTaskItemDialg(list){
    const dialgRef = this.dialog.open(ConfirmDialogComponent ,{ data: {title:"删除列表",content:"是否确定删除当前里列表？"} });
    dialgRef.afterClosed().subscribe(result => console.log(result,JSON.stringify(list)))
  }
  lanuchEidetListName(list){
    const dialgRef = this.dialog.open(NewTaskListComponent ,{ data: {title:"修改列表"} });
    dialgRef.afterClosed().subscribe(result => console.log(result,JSON.stringify(list)))
  }
  lanuchListNewClickDialg(){
    const dialgRef = this.dialog.open(NewTaskListComponent ,{ data: {title:"新增列表"} });
    dialgRef.afterClosed().subscribe(result => console.log(result))
  }

  // 拖拽
  handLeMove(srcData,list){
    switch (srcData.tag) {
      case 'task-item': {
       console.log("item-------drop")
        break;
      }
      case 'task-list': {
        console.log("lists-------drop")
      }
      default:
        break;
    }
  }

  handeQuickTask(desc:string){
    console.log(desc)
  }

}
